/*
package com.jymj.controller;

import com.jymj.entity.CjEntity;
import com.jymj.entity.SysUserEntity;
import com.jymj.entity.YlEntity;
import com.jymj.entity.zjd.ZjdFileEntity;
import com.jymj.entity.zjd.ZjdSqEntity;
import com.jymj.service.LandService;
import com.jymj.service.YlService;
import com.jymj.service.ZjdFileService;
import com.jymj.service.ZjdSqService;
import com.jymj.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

*/
/**
 * Created by dl on 2019/10/16.
 * 宅基地申请
 *//*

@RestController
@RequestMapping("zjdSq")
public class ZjdSqController extends AbstractController {
    private final String SAVE_PATH = "zjdSqFile";
    @Autowired
    private ZjdFileService zjdFileService;
    @Autowired
    private ZjdSqService zjdSqService;
    @Autowired
    private YlService ylService;
    @Autowired
    private LandService landService;


    //申请流程列表
    @RequestMapping("/")
    public R queryList(@RequestBody Map<String, Object> params){
        Integer sptype = null;
        Integer limit = null;
        Integer page = null;
        String xzqmc = null;
        String point = null;
        ArrayList list = null;
        if (params.get("sptype") != null && params.get("sptype") != null){
            sptype = Integer.parseInt(params.get("sptype").toString());
        }
        if (params.get("limit") != null && params.get("limit") != null){
            limit = Integer.parseInt(params.get("limit").toString());
        }
        if (params.get("page") != null && params.get("page") != null){
            page = Integer.parseInt(params.get("page").toString());
        }
        if (params.get("xzqmc") != null && params.get("xzqmc") != null){
            xzqmc =  params.get("xzqmc").toString();
        }
        if (params.get("point") != null && params.get("point") != null){
            point =  params.get("point").toString();
        }
        if(params.containsKey("codeList") && params.get("codeList") != null){
            String codes  = params.get("codeList").toString();
            String i = codes.substring(1,codes.length()-1);
            String str= i.replace("\"", "");
            list = new ArrayList(Arrays.asList(str.split(",")));
        }

        List<ZjdSqEntity> zjdSqEntities = null;
        int total = 0;
        if (params != null && page != null && limit != null){
            Query query = new Query(params);
            query.put("sptype", sptype);
            query.put("xzqmc",xzqmc);
            query.put("point",point);
            query.put("codeList",list);
            zjdSqEntities = zjdSqService.queryList(query);
            total = zjdSqService.queryTotal(query);
        }else {
            zjdSqEntities = zjdSqService.queryList(params);
            total = zjdSqService.queryTotal(params);
        }
        if (limit == null){
            limit = 0;
        }
        if (page == null){
            page = 0;
        }
        PageUtils pageUtil = new PageUtils(zjdSqEntities, total, limit, page);
        return R.ok().put("data",pageUtil);
    }

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public R info(@RequestBody Map map){
        Integer id = null;
        if (map.containsKey("id") && map.get("id") != null){
            id = Integer.valueOf(map.get("id").toString());
        }
        if(id==null){
            return R.error("网络错误");
        }
        Integer[] ids = {id};
        List<ZjdSqEntity> zjdSqEntityList = zjdSqService.queryListById(ids);
        return R.ok().put("data",zjdSqEntityList.get(0));
    }

    */
/*
* 图表情况
* *//*

    @RequestMapping("/queryTypeCount")
    public R queryTypeCount(@RequestBody Map map){
        String xzqmc = null;
        if (map.containsKey("xzqmc") && map.get("xzqmc") != null){
            xzqmc = map.get("xzqmc").toString();
        }
        Integer type = null;
        if (map.containsKey("type") && map.get("type") != null){
            type = Integer.valueOf(map.get("type").toString());
        }
        List<ZjdSqEntity> zjdSqEntities = zjdSqService.queryTypeCount(xzqmc,type);
        return R.ok().put("data",zjdSqEntities);
    }

    */
/**
     * 点查询
     *
     *  point
     * @return R
     *//*

    @RequestMapping("/exitlyByPoint")
    public R list(@RequestBody Map map) {
        String point = null;
        if (map.containsKey("point") && map.get("point") != null){
            point = map.get("point").toString();
        }
        boolean b = landService.queryIstrue(point);
        if (b == false){
            return R.error("超出范围");
        }
        ZjdSqEntity zjdSqEntity = new ZjdSqEntity();
        SysUserEntity user = getUser();
        YlEntity ylEntity = ylService.getYLbyPoint(point, user.getCode());
        if (ylEntity != null && ylEntity.getObjectid() != null) {
            zjdSqEntity = zjdSqService.queryObjectByylId(ylEntity.getObjectid());
        }
        return R.ok().put("data", zjdSqEntity);
    }

    @RequestMapping("/qurtyGeom")
    public R qurtyGeom(@RequestBody Map map){
        String geom = null;
        if (map.containsKey("geom") && map.get("geom") != null){
            geom = map.get("geom").toString();
        }
        //查找框选
        if (geom!= null){
            //判断框选是否有数据
            List<YlEntity> ylEntityList = ylService.queryYl(geom);
            if (ylEntityList == null || ylEntityList.size() == 0){
                CjEntity cjEntity = zjdSqService.queryXzq(geom);
                if (cjEntity == null){
                    return R.error("请框选在村内位置");
                }
                return R.ok();
            }else {
                return R.error("框选不能有数据");
            }
        }else{
            return R.error();
        }
    }

    */
/*
    * 申请人添加申请
    * *//*

    @RequestMapping("/save")
    @Transactional
    public R save(@RequestBody ZjdSqEntity zjdSqEntity){
        //判断资料是否全
        if (zjdSqEntity.getFileIds() == null || zjdSqEntity.getFileIds().size() == 0){
            return R.error("请补全资料");
        }
        boolean istrue = zjdSqService.queryAllFile(1,zjdSqEntity.getFileIds());
        if (!istrue){
            return R.error("请补全资料");
        }
        if(zjdSqEntity.getRemark()!=null){
            zjdSqEntity.setRemark("申请备注："+zjdSqEntity.getRemark()+"\n");
        }
        String geom = null;
        if(zjdSqEntity.getGeom() != null){
            geom = zjdSqEntity.getGeom().replace("POLYGON","MultiPolygon(");
            geom = geom + ")";
        }
        CjEntity cjEntity = zjdSqService.queryXzq(zjdSqEntity.getGeom());
        YlEntity ylEntity = new YlEntity();
        ylEntity.setCenter(zjdSqEntity.getGeom());
        ylEntity.setXzqmc(cjEntity.getXzqmc());
        ylEntity.setCode(cjEntity.getCode());
        ylEntity.setHzmc(zjdSqEntity.getSqName());
        ylEntity.setGeometry(geom);
        ylEntity.setSqtype(1);
        ylEntity.setLegent(1);
        ylEntity.setYlType(1);
        ylService.save(ylEntity);
        YlEntity ylEntity1 = ylService.queryByGid(ylEntity.getGid());
        zjdSqEntity.setYlId(ylEntity1.getObjectid());
        zjdSqEntity.setSptype(1);
        zjdSqEntity.setSqDate(new Date());
        zjdSqService.save(zjdSqEntity);
        zjdFileService.updateZjdId(zjdSqEntity.getId(),zjdSqEntity.getFileIds());
        return R.ok();
    }

    */
/*
   * 审批 下一步
   * *//*

    @RequestMapping("/approval")
    public R approval(@RequestBody ZjdSqEntity zjdSqEntity){
        //判断材料是否齐全
        ZjdSqEntity zjdSqEntity1 = zjdSqService.queryObject(zjdSqEntity.getId());
        if(zjdSqEntity.getRemark()!=null){
            zjdSqEntity.setRemark(zjdSqEntity1.getRemark() + zjdSqEntity.getSptypeText() + "备注："+zjdSqEntity.getRemark()+"\n");
        }
        if (zjdSqEntity.getSptype()> zjdSqEntity1.getSptype()){
            if (zjdSqEntity.getSptype() == 1){
                boolean istrue = zjdSqService.queryAllFile(zjdSqEntity.getSptype(),new ArrayList<>());
                if (!istrue){
                    return R.error("请补全资料");
                }
            }else if (zjdSqEntity.getSptype() == 5){
                zjdSqEntity.setBhDate(new Date());
                int i = zjdSqService.update(zjdSqEntity);
                zjdSqService.updateYl(zjdSqEntity1.getYlId(),zjdSqEntity.getSptype());
                return R.ok();
            }else {
                boolean istrue = zjdSqService.queryCount(zjdSqEntity.getSptype(),zjdSqEntity.getId());
                if (!istrue){
                    return R.error("请补全资料");
                }
            }
        }else {
            return R.error();
        }
        int i = zjdSqService.update(zjdSqEntity);
        zjdSqService.updateYl(zjdSqEntity1.getYlId(),zjdSqEntity.getSptype());
        return R.ok();
    }

    */
/*
    * 删除
    * *//*

    @RequestMapping(value = "/delete")
    public R delete(@RequestBody Map map, HttpServletRequest request) throws FileNotFoundException {
        File genPath=new File(ResourceUtils.getURL("jar:").getPath());
        File savePath=new File(genPath.getAbsolutePath().replace("jar:","fileupload"));
        Integer[] ids = null;
        if (map.containsKey("ids") && map.get("ids") != null){
            String codes  = map.get("ids").toString();
            ArrayList list = new ArrayList(Arrays.asList(codes.split(",")));
            ids = Arrays.stream(list.toArray(new String[list.size()])).map(p ->
                    Integer.valueOf(p.toString())).toArray(Integer[]::new);
        }
        List<ZjdSqEntity> zjdSqEntities = zjdSqService.queryListById(ids);
        if(zjdSqEntities!=null && zjdSqEntities.size()>0){
            for (ZjdSqEntity zjdsq:zjdSqEntities) {
                if(zjdsq.getZjdFileEntityList()!=null){
                    for (ZjdFileEntity zjdFile:zjdsq.getZjdFileEntityList()) {
                        File file=new File(savePath + File.separator + zjdFile.getPath());
                        if(file.exists()){
                            file.delete();
                        }
                    }
                }
                //删除院落信息
                ylService.deleteByObjectid(zjdsq.getYlId());
            }
            zjdSqService.deleteBatch(ids);
        }
        return R.ok();
    }


    */
/**
     * 上传图片
     *//*

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public R uploadFile(HttpServletRequest request) throws FileNotFoundException {
        Map<String, Object> map = new HashMap();
        //资料表实体
        List<ZjdFileEntity> fileList = new ArrayList<>();
        ZjdFileEntity zjdFileEntity = new ZjdFileEntity();
        // 获取根目录的绝对路径
        File genPath=new File(ResourceUtils.getURL("classpath:").getPath());
        if(!genPath.exists()){
            genPath=new File("");
        }
        //在开发测试模式时，得到地址为：{项目跟目录}/target/progress/
        //在打成jar正式发布时，得到的地址为:{发布jar包目录}/progress/
        File savePath=new File(genPath.getAbsolutePath(),"fileupload"+ File.separator+SAVE_PATH);
        File savePath1=new File(genPath.getAbsolutePath(),"fileupload");
        if(!savePath.exists()){
            savePath.mkdirs();
            System.out.println("文件路径为：+"+savePath.getAbsolutePath());
        }
        //if (multipartResolver.isMultipart(request)) {
        //转换成多部分request
        MultipartHttpServletRequest multiRequest =null;
        if (request instanceof MultipartHttpServletRequest) {
            multiRequest = (MultipartHttpServletRequest)(request);
        }else {
            return R.error("文件不能为空！");
        }
        String key = multiRequest.getParameter("key");//文件类型
        String status = multiRequest.getParameter("status");//流程状态
        String remark = null;
        if (multiRequest.getParameter("remark") != null){
            remark = multiRequest.getParameter("remark");//备注
        }
        Integer zjdId = null;
        if (multiRequest.getParameter("zjdId") != null){
            zjdId = Integer.parseInt(multiRequest.getParameter("zjdId"));
        }
        //取得request中的所有文件名
        Iterator<String> iter = multiRequest.getFileNames();
        while (iter.hasNext()) {
            //取得上传文件
            MultipartFile file = multiRequest.getFile(iter.next());
            if (file != null) {
                //取得当前上传文件的文件名称
                String myFileName = file.getOriginalFilename();
                //如果名称不为“”,说明该文件存在，否则说明该文件不存在
                if (!"".equals(myFileName.trim())) {
                    //重命名上传后的文件名
                    String fileName = file.getOriginalFilename();
                    //System.out.println(savePath + "\\" + fileName);
                    zjdFileEntity.setFilename(fileName);
                    String ext = fileName.substring(fileName.indexOf("."));
                    TimeString st = new TimeString();
                    zjdFileEntity.setPath(SAVE_PATH+ File.separator+st.getTimeString() + ext);
                    zjdFileEntity.setUpdate(new Date());
                    zjdFileEntity.setZjdId(zjdId);
                    zjdFileEntity.setKey(Integer.parseInt(key));
                    zjdFileEntity.setStatus(Integer.parseInt(status));
                    zjdFileEntity.setType(3);
                    zjdFileEntity.setRemark(remark);
                    fileList.add(zjdFileEntity);
                    //上传路径
                    String path = savePath1 + File.separator + zjdFileEntity.getPath();
                    File localFile = new File(path);
                    try {
                        file.transferTo(localFile);
                    } catch (IOException e) {
                        return R.error("上传失败").put("code", 500);
                    }
                }
            } else {
                return R.error("文件不能为空！");
            }
        }
        //}
        List<ZjdFileEntity> zjdFileIds= zjdFileService.saveFileBatch(fileList);
        return R.ok().put("data",zjdFileIds);
    }
}
*/
